#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

vector<string> anagrams(vector<string> &strs);

int main(int argc, char **argv){

    vector<string> strs;
    strs.push_back("abc");
    strs.push_back("dcd");
    strs.push_back("cab");
    vector<string> res = anagrams(strs);
    for(vector<string>::iterator it = res.begin();
        it != res.end();
        ++it){
        cout<<*it<<endl;
    }


    return 0;
}

vector<string> anagrams(vector<string> &strs) {
    // Start typing your C/C++ solution below
    // DO NOT write int main() function
    map<string, vector<string> > dict;
    for(vector<string>::iterator it = strs.begin();
        it != strs.end();
        ++it){
        string tmp = *it;
        sort(tmp.begin(), tmp.end());
        dict[tmp].push_back(*it);
    }
    vector<string> res;
    for(map<string, vector<string> >::iterator it = dict.begin();
        it != dict.end();
        ++it){

        if(it->second.size() > 1){
            for(vector<string>::iterator iit =  it->second.begin();
                iit != it->second.end();
                ++iit){
                    res.push_back(*iit);
            }
        }
    }
    return res;
}